import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:totaldemo/getx/controller.dart';

class GetxBuilderPage extends StatelessWidget {
  GetxBuilderPage({Key key}) : super(key: key);
  final controller = GetXBuilderController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('getxbuilder'),
      ),
      body: Center(
        child: Column(
          children: [
            GetBuilder<GetXBuilderController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print('buider 1号');
                return Text('value -> ${_.count3}');
              },
            ),
            GetBuilder<GetXBuilderController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print("GetBuilder - 2号");
                return Text('value -> ${_.count3}');
              },
            ),
            Divider(),
            //
            GetBuilder<GetXBuilderController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print('GetBuilder  -3号');
                return Column(
                  children: [
                    Text('value -> ${_.count3}'),
                    ElevatedButton(
                        onPressed: () {
                          _.add3();
                        },
                        child: Text('getbuilder --> add'))
                  ],
                );
              },
            ),
            Divider(),
//count2
            GetBuilder<GetXBuilderController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print("GetBuilder - 4");
                return Text('value 二档-> ${_.count4}');
              },
            ),
            Divider(),
//有id的
            GetBuilder<GetXBuilderController>(
              id: 'id2',
              init: controller,
              initState: (_) {},
              builder: (_) {
                print('GetBuilder  -4号');
                return Text('有id的-二档-> ${_.count4}');
              },
            ),
            Divider(),
//按钮
            ElevatedButton(
                onPressed: () {
                  controller.add3();
                },
                child: Text('add--添加上面的')),
            ElevatedButton(
                onPressed: () {
                  controller.add4();
                },
                child: Text('add2--添加下面的')),
            ElevatedButton(
                onPressed: () {
                  controller.update();
                },
                child: Text('手动更新所有')),
            ElevatedButton(
                onPressed: () {
                  controller.update(['id2']);

                  ///传的是一个list
                },
                child: Text('指定更新（id=2）')),
          ],
        ),
      ),
    );
  }
}
